package com.example.demo.pattern.singleton;

/**
 * 懒汉式，线程安全
 * 是否 Lazy 初始化：是
 * 是否多线程安全：是
 * 实现难度：易
 * 必须加锁 synchronized 才能保证单例，但加锁会影响效率
 */
public class LazySafeSingleton {

    private static LazySafeSingleton instance;

    private LazySafeSingleton() {
    }

    public static synchronized LazySafeSingleton getInstance(){
        if (instance == null){
            instance = new LazySafeSingleton();
        }
        return instance;
    }
}
